package cn.iocoder.yudao.module.wrdk.controller.admin.land;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wrdk.controller.admin.land.vo.*;
import cn.iocoder.yudao.module.wrdk.dal.dataobject.land.wrdklandDO;
import cn.iocoder.yudao.module.wrdk.convert.land.wrdklandConvert;
import cn.iocoder.yudao.module.wrdk.service.land.wrdklandService;

@Api(tags = "Crazy!!!!!管理后台 - 污染地块安全利用率调查")
@RestController
@RequestMapping("/wrdk/wrdkland")
@Validated
public class wrdklandController {

    @Resource
    private wrdklandService wrdklandService;

    @PostMapping("/create")
    @ApiOperation("创建污染地块安全利用率调查")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkland:create')")
    public CommonResult<Long> createwrdkland(@Valid @RequestBody wrdklandCreateReqVO createReqVO) {
        return success(wrdklandService.createwrdkland(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新污染地块安全利用率调查")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkland:update')")
    public CommonResult<Boolean> updatewrdkland(@Valid @RequestBody wrdklandUpdateReqVO updateReqVO) {
        wrdklandService.updatewrdkland(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除污染地块安全利用率调查")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkland:delete')")
    public CommonResult<Boolean> deletewrdkland(@RequestParam("id") Long id) {
        wrdklandService.deletewrdkland(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得污染地块安全利用率调查")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkland:query')")
    public CommonResult<wrdklandRespVO> getwrdkland(@RequestParam("id") Long id) {
        wrdklandDO wrdkland = wrdklandService.getwrdkland(id);
        return success(wrdklandConvert.INSTANCE.convert(wrdkland));
    }

    @GetMapping("/list")
    @ApiOperation("获得污染地块安全利用率调查列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkland:query')")
    public CommonResult<List<wrdklandRespVO>> getwrdklandList(@RequestParam("ids") Collection<Long> ids) {
        List<wrdklandDO> list = wrdklandService.getwrdklandList(ids);
        return success(wrdklandConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得污染地块安全利用率调查分页")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkland:query')")
    public CommonResult<PageResult<wrdklandRespVO>> getwrdklandPage(@Valid wrdklandPageReqVO pageVO) {
        PageResult<wrdklandDO> pageResult = wrdklandService.getwrdklandPage(pageVO);
        return success(wrdklandConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出污染地块安全利用率调查 Excel")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkland:export')")
    @OperateLog(type = EXPORT)
    public void exportwrdklandExcel(@Valid wrdklandExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<wrdklandDO> list = wrdklandService.getwrdklandList(exportReqVO);
        // 导出 Excel
        List<wrdklandExcelVO> datas = wrdklandConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "污染地块安全利用率调查.xls", "数据", wrdklandExcelVO.class, datas);
    }

    @DeleteMapping("/delete/select")
    @ApiOperation("删除多选的污染地块目录")
    public CommonResult<Boolean> deleteSelectWrdk(@RequestParam("ids") List<Long> ids) {
        wrdklandService.deleteSelectLand(ids);
        return success(true);
    }

}
